package com.systemsjr.mpf.expense;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;

import android.net.Uri;

import com.systemsjr.mpf.account.AccountInstance;
import com.systemsjr.mpf.db.ExpenseContentProvider;

public class Expense implements Serializable, Cloneable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1395662668637683071L;

	// THE CONTENT URI TO OUR PROVIDER
	public static final Uri CONTENT_URI = Uri.parse("content://"
			+ ExpenseContentProvider.AUTHORITY + "/expense");

	// MIME TYPE FOR GROUP OF ACCOUNTS
	public static final String CONTENT_TYPE = "vnd.android.cursor.dir/com.systemsjr.mpf.expense";

	// MIME TYPE FOR SINGLE ACCOUNT
	public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/com.systemsjr.mpf.expense";

	public static final int TYPE_PATH_POSITION = 7;
	public static final int INSTANCE_PATH_POSITION =2;
	public static final int AMOUNT_LESS_POSITION = 3;
	public static final int AMOUNT_MORE_POSITION = 4;
	public static final int DATE_LESS_POSITION = 5;
	public static final int DATE_MORE_POSITION = 6;
	public static final int DESCRIPTION_POSITION = 1;
	
	public static String TABLE_NAME = "EXPENSE";

	public static String ID = "_id";
	public static String EXPENSE_TYPE = "EXPENSE_TYPE_FK";
	public static String AMOUNT = "AMOUNT";
	public static String EXPENSE_DATE = "EXPENSE_DATE";
	public static String ACCOUNT_INSTANCE = "ACCOUNT_INSTANCE_FK";
	public static String DESCRIPTION = "DESCRIPTION";
	public static String DATE_FORMAT = "yyyy-MM-dd HH:mm";
	
	public static final String[] PROJECTIONS = { Expense.ID,
		Expense.ACCOUNT_INSTANCE, Expense.EXPENSE_TYPE,
		Expense.DESCRIPTION, Expense.AMOUNT, Expense.EXPENSE_DATE };
	
	private Long id;
	private double amount;
	private String description;
	private Date expenseDate;
	private AccountInstance accountInstance;
	private ExpenseType expenseType;

	public Expense() {
		// expenseDate = DateUtils.
	}

	public Expense(long id, double amount, String description,
			Timestamp expenseDate) {
		super();
		this.id = id;
		this.amount = amount;
		this.description = description;
		this.expenseDate = expenseDate;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getExpenseDate() {
		return expenseDate;
	}

	public void setExpenseDate(Date expenseDate) {
		this.expenseDate = expenseDate;
	}

	public AccountInstance getAccountInstance() {
		return accountInstance;
	}

	public void setAccountInstance(AccountInstance accountInstance) {
		this.accountInstance = accountInstance;
	}

	public ExpenseType getExpenseType() {
		return expenseType;
	}

	public void setExpenseType(ExpenseType expenseType) {
		this.expenseType = expenseType;
	}

	public static String createTable() {
		return "CREATE TABLE " + TABLE_NAME + "(" + ID
				+ " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + EXPENSE_DATE
				+ " DATETIME not null DEFAULT CURRENT_TIMESTAMP," + AMOUNT
				+ " DOUBLE not null," + DESCRIPTION + " TEXT BINARY not null,"
				+ ACCOUNT_INSTANCE + " INTEGER not null," + EXPENSE_TYPE
				+ " INTEGER not null)";
	}
	
	public Expense clone(){
		Expense e = new Expense();
		
		e.setAccountInstance(accountInstance);
		e.setAmount(amount);
		e.setDescription(description);
		e.setExpenseDate(expenseDate);
		e.setExpenseType(expenseType);
		e.setId(id);
		
		return e;
	}
}
